package cn.itsource.pet.controller;

import cn.itsource.basic.util.AjaxResult;
import cn.itsource.basic.util.PageList;
import cn.itsource.pet.domain.PetType;
import cn.itsource.pet.query.PetTypeQuery;
import cn.itsource.pet.service.IPetTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 宠物类型控制器
 */
@RestController
@RequestMapping("/petType")
@Api(tags = "宠物类型管理", description = "宠物类型操作接口")
public class PetTypeController {

    @Autowired
    private IPetTypeService petTypeService;

    /**
     * 查询多级联动
     */
    @GetMapping("/tree")
    @ApiOperation(value = "查询所有宠物类型信息", notes = "查询所有宠物类型信息，get请求")
    public List<PetType> findManyLevelPetType() {
        return petTypeService.findManyLevelPetType();
    }


    /**
     * 查询所有
     */
    @GetMapping
    @ApiOperation(value = "查询所有宠物类型信息", notes = "查询所有宠物类型信息，get请求")
    public List<PetType> findAll() {
        return petTypeService.findAll();
    }

    /**
     * 查询分页数据
     */
    @PostMapping("/findPage")
    @ApiOperation(value = "查询部门分页数据", notes = "查询数据")
    public PageList<PetType> findPage(@RequestBody PetTypeQuery petTypeQuery) {
        //查询分页数据
        return petTypeService.findPage(petTypeQuery);
    }

    /**
     * 新增或修改的操作
     * 根据id来区分新增和修改
     * 怎么区分请求使用的请求方式  这里是post
     */
    @PostMapping
    public AjaxResult saveOrUpdate(@RequestBody PetType petType) {

        //没有id就是新增
        petTypeService.saveOrUpdate(petType);

        //返回成功对象
        return AjaxResult.createSuccess();
    }

    /**
     * 删除操作
     */
    @DeleteMapping("{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {

        petTypeService.delete(id);
        //返回成功对象
        return AjaxResult.createSuccess();

    }

    /**
     * 批量删除操作
     */
    @PostMapping("/batchDelete")
    public AjaxResult delete(@RequestBody PetTypeQuery petTypeQuery) {

        //批量删除操作
        petTypeService.batchDelete(petTypeQuery);
        //返回成功对象
        return AjaxResult.createSuccess();
    }


}
